package org.argeproje.resim.proc.fuzzy;

import org.argeproje.resim.proc.FunctionPR;
import org.argeproje.resim.proc.PerPixelFunctionI;
import org.argeproje.resim.proc.Processor;
import org.argeproje.resim.proc.data.Data;


public class IncreaseContrastPR extends Processor implements PerPixelFunctionI{


	@Override
	public Data process() {
       FunctionPR pr = new FunctionPR();
       pr.setParameters(this);
       pr.setInput(getInput());
	   setOutput(pr.process());
	   return 	getOutput();
	}

	public float processSample(int x, int y, int band, float value) {
		float result = (getMdark(value) * 0.0F +
			getMgray(value) * 128.0F + getMbright(value) * 255.0F) /
			(getMdark(value) + getMgray(value) + getMbright(value));
		return result;
	}
	float getMdark(float value){
		float a = 30.0F;
		float b = 128.0F;
		float result = 1.0F;
		if (value >= b){
			result = 0.0F;
		}else if(value <= a){
			result = 1.0F;
		}else{
			result = (b - value) / (b - a);
		}
		return result;
	}
	float getMgray(float value){
		float a = 128 - 30;
		float b = 128 + 30;
		float result = 0.0F;
		if ((value <= 128.0F) && (value > a)){
			result = (value - a) / (128.0F - a);
		}else if((value <= b) && (value > 128)){
			result = (b - value) / (b - 128.0F);
		}	
		return result;
	}
	float getMbright(float value){
		float a = 128.0F;
		float b = 220.0F;
		float result = 1.0F;
		if (value <= a){
			result = 0.0F;
		}else if(value < b){
			result = (value - a) / (b - a);
		}
		return result;
	}
}